/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.rcs.adslmonitor;

import javax.swing.table.AbstractTableModel;

/**
 *
 * @author pablo
 */
public class ADSLStatusModel extends AbstractTableModel {

    private ADSLStatus status;

    public ADSLStatusModel(ADSLStatus adslStatus) {
        status = adslStatus;
    }

    public int getRowCount() {
        if (status.hasError()) {
            return 1;
        } else {
            return 2;
        }
    }

    public int getColumnCount() {
        if (status.hasError()) {
            return 1;
        } else {
            return 4;
        }
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        if (status.hasError())
            return status.getLastError() ;
        else
        {
            ADSLStatus.KEYS[] keys = ADSLStatus.KEYS.values() ;
            ADSLStatus.KEYS key ;

            if (0 == rowIndex)
                key = keys[4 + columnIndex] ;
            else
                key = keys[columnIndex] ;

            return status.get(key) ;
        }
    }

    public void refresh() {
        boolean hasError = status.hasError();

        if (hasError != status.refresh()) {
            fireTableStructureChanged();
        } else {
            fireTableDataChanged();
        }
    }

    public ADSLStatus getADSLStatus() {
        return status ;
    }

    public String getColumnName(int column) {
        if (status.hasError())
            return "Error" ;
        else
        {
            switch (column) {
                case 0:
                    return "Actual" ;
                case 1:
                    return "Max" ;
                case 2:
                    return "Atenuación" ;
                default:
                    return "Margen de ruido" ;
            }
        }
    }
}
